/**
 * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.opsli.modulars.customer.customerrelation.service;

import lombok.extern.slf4j.Slf4j;
import org.opsli.api.wrapper.customer.customerrelation.CustomerStudentRelationModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 客户业务服务
 * 用于处理跨模块的业务逻辑，避免循环依赖
 *
 * @author guagua
 * @date 2025-01-04
 */
@Slf4j
@Service
public class CustomerBusinessService {

    @Autowired
    private ICustomerStudentRelationService customerStudentRelationService;

    /**
     * 验证客户关系是否存在
     *
     * @param customerId 客户ID
     * @return 是否存在
     */
    public boolean validateCustomerRelationExists(String customerId) {
        try {
            CustomerStudentRelationModel model = new CustomerStudentRelationModel();
            model.setId(customerId);
            model.setIzApi(true);
            CustomerStudentRelationModel result = customerStudentRelationService.get(model);
            return result != null;
        } catch (Exception e) {
            log.error("验证客户关系是否存在失败，customerId: {}", customerId, e);
            return false;
        }
    }

    /**
     * 验证客户是否存在（通过客户ID）
     *
     * @param customerId 客户ID
     * @return 是否存在
     */
    public boolean validateCustomerExists(String customerId) {
        try {
            CustomerStudentRelationModel model = new CustomerStudentRelationModel();
            model.setId(customerId);
            model.setIzApi(true);
            CustomerStudentRelationModel result = customerStudentRelationService.get(model);
            return result != null;
        } catch (Exception e) {
            log.error("验证客户是否存在失败，customerId: {}", customerId, e);
            return false;
        }
    }

}